import axios from 'axios'

export default {
  namespaced: true,
  state: {
    token: localStorage.getItem('token') ? localStorage.getItem('token') : '',
    userInfo: {}
  },
  getters: {
  },
  mutations: {
    updateToken(state, payload) {
      state.token = payload
      localStorage.setItem('token', payload)
    },
    updataUserInfo(state, info) {
      state.userInfo = info
    }
  },
  actions: {
    async initUserInfo(content) {
      // console.log(content)
      const { data: res } = await axios.get('/my/userinfo', {
        headers: {
          Authorization: content.state.token
        }
      })
      if (res.code !== 0) return
      console.log(res)
      content.commit('updataUserInfo', res.data)
    }
  },
  modules: {
  }
}
